<extend name="./app/Tpl/Public/template.html" />
<block name="content_body">
	<div class="pad-lr-10">
		<form name="form_search" id="form_search" action="{:U('index')}" method="post">
		    <table width="100%" cellspacing="0" class="search-form">
		        <tbody>
		            <tr>
			            <td>
				            <div class="explain-col">							
								<select name="cate_code" style="width:250px;" class="chosen_search">
									<option value="">全部分类列表</option>
	                				<volist name="cateTree" id="val_1">
								    	<option value="{$val_1.code}"  <if condition="$val_1['code'] eq $search['cate_code']">selected</if>>{$val_1.code}-{$val_1.title}</option>
										<volist name="val_1['children']" id="val_2">
											<option value="{$val_2.code}"  <if condition="$val_2['code'] eq $search['cate_code']">selected</if>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$val_2.code}{$val_2.title}</option>								
										</volist>
	                				</volist>
								</select>
								<select name="is_show" style="width:150px;" class="chosen_search">
									<option value="">--是否上架--</option>
									<option value="1" <if condition="$search['is_show'] eq '1'">selected</if>>已上架</option>
	                				<option value="0" <if condition="$search['is_show'] eq '0'">selected</if>>未上架</option>
								</select>
								<input type="text" name="name" value="{$search.name}" placeholder="商品名称">
								<input type="text" name="brand" value="{$search.brand}" placeholder="品牌">
								<input type="button"  name="form_search_btn_search"  value="查询" onclick="document.forms['form_search'].submit()"/>	
								<a href="{:U('doRefreshBrand')}" >刷新分类品牌</a>	
				        	</div>
			            </td>
		            </tr>
		        </tbody>
		    </table>
	    </form>
	    <form  name="form_list" id="form_list" action="{:U('index')}" method="post">
	    	<input type="hidden" name="auth_type" value="group">
		    <div class="table-list">		
			    <table width="100%" cellspacing="0">
			        <thead>
			            <tr>
			            	<th width="40" align="center">图片</th> 
			            	<th width="40" align="center">选中</th>  
			            	<th width="60" align="left">条形码</th>               
			                <th width="120" align="left">商品名称</th>
			                <th width="70" align="left">实际价格</th>
			                <th width="70" align="left">原价</th>
			                <th width="70" align="left">会员价</th>
			                <th width="80" align="left">规格/单位</th>
			      			<th width="40" align="left">热门</th>
			      			<th width="40" align="left">推荐</th>
			      			<th width="40" align="left">上架</th>
			      			<th width="40" align="left">排序</th>
			      			<th align="left">操作</th>
			            </tr>
			        </thead>
			    	<tbody>
						<volist name="list" id='val'>
				        <tr>
				        	<td align="center"><img src="{$val.prod_id|m_prod_pic}?{$Think.now} "  id="pic_{$val.prod_id}" width=45  height=30></td>
				            <td align="center"><input type="checkbox" value="{$val.prod_id}" name="id[]"></td>
				            <td align="left">{$val.barcode}</td>
				            <td align="left"><span>{$val.name}</span></td>
				            <td align="left">
				            	<input type="text" class="input-text-c input-text" value="{$val.price_real}" size="6" name="price_real[]" id="price_real{$val.prod_id}">
				            </td>
				            <td align="left">
				            	<input type="text" class="input-text-c input-text" value="{$val.price_sale}" size="6" name="price_sale[]" id="price_sale{$val.prod_id}">
				            </td>
				            <td align="left">
				            	<input type="text" class="input-text-c input-text" value="{$val.price_vip}" size="6" name="price_vip[]" id="price_vip{$val.prod_id}">
				            </td>
				            <td align="left">{$val.spec|m_prod_spec=$val['spec_qty'],$val['spec_unit']}</td>
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_hot')" id="is_hot_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_hot}.png" /></td>
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_recommend')" id="is_recommend_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_recommend}.png" /></td>
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_show')" id="is_show_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_show}.png" /></td>
				            <td align="left">
				            	<input type="text" class="input-text-c input-text" value="{$val.ordlist}" size="4" name="ordlist[{$val.id}]" id="ordlist_{$val.id}" onblur="ordlist('{:U('ordlist')}',{$val.id},'ordlist',this.value)"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
								<span id="ordlist_upd_{$val.id}" value="{$val.ordlist}"></span>
							</td>
				            <td align="left" class="btn">
				            	<a class="link_btn" href="#" onclick="doUpd('{:U('doUpdPrice')}','{$val.prod_id}');return false;" >改价</a>
				            	<a class="link_btn" href="#" onclick="openDialogLog('{:U('Product/ProductLogManage/showList')}','{$val.prod_id}','price');return false;" >历史</a>
				            	
				            </td>
				        </tr>
				        </volist>
			    	</tbody>
			    </table>
	
			    <div class="btn">
					<input type="button"  name="form_list_btn_ckAll" class="ckSelect" ck_type="all" ck_name="id[]" value="全选" />
					<input type="button"  name="form_list_btn_ckNone" class="ckSelect" ck_type="none"  ck_name="id[]" value="全不选" />
					<input type="button"  name="form_list_btn_ckReverse" class="ckSelect" ck_type="reverse" ck_name="id[]" value="反选"/>
					<input type="button"  name="form_list_btn_ckDel" value="批量编辑价格" onclick="doUpdBatch('{:U('showUpdBatch')}')"/>
					<input type="button"  name="form_list_btn_ckDel" value="删除选中项" onclick="doDel('{:U('doDel')}')"/>
					<div id="pages">{$page}</div>
			    </div>
	    	</div>
	    </form>
	</div>
	<div id="dialog_content" title="弹出框"></div>
<script type="text/javascript">

$(function(){
	//打开编辑窗口
	$( "#dialog_content" ).dialog({
		autoOpen: false,
		width:600,
		height:400
	});
})

//显示变更历史窗口
function openDialogLog(action_url,prod_id,type){
	$.post(
		action_url, 
		{"prod_id":prod_id,"type":type}, 
		function(htmldata){
			$("#dialog_content").dialog("option","title","价格变更记录");
			$("#dialog_content").html(htmldata).dialog("open");
		},
		"html"
	);
	return false;
}

function doUpd(action_url,prod_id){
	var price_real = $('#price_real'+prod_id).val();
	var price_sale = $('#price_sale'+prod_id).val();
	var price_vip = $('#price_vip'+prod_id).val();
	if(!checkRegex(price_real,regexEnum.decmal1)){
		alert("请输入正确的实际价格");
		return false;
	}
	if(!checkRegex(price_sale,regexEnum.decmal1)){
		alert("请输入正确的推荐价格");
		return false;
	}
	if(!checkRegex(price_vip,regexEnum.decmal1)){
		alert("请输入正确的会员价");
		return false;
	}
	
	$.get(action_url, { prod_id: prod_id, price_real: price_real, price_sale: price_sale, price_vip: price_vip }, function(jsondata){
		if(jsondata['error']==0){
			alert('价格更新成功');
			$('#price_real'+prod_id).css('color','blue');
			$('#price_sale'+prod_id).css('color','blue');
			$('#price_vip'+prod_id).css('color','blue');
			return false;
		}else{
			if(jsondata['message']==''){
				alert('数据未发生变化');
			}else{
				alert(jsondata['message']);
			}
			return false;
		}
	},'json'); 
	
}

function doUpdBatch(action_url){
	$("#form_list").attr('action',action_url);
	$("#form_list").submit();
}


//删除操作
function doDel(action_url){
	if(confirm("确定删除选中的运价？")){
		$("#form_list").attr('action',action_url);
		$("#form_list").submit();
	}
	
}

//刷新菜单缓存文件
function removeCache(){
	$.get("{:U('removeCache')}", { }, function(jsondata){ 
		alert(jsondata);
	},'json'); 
}
</script>
</block>